package com.timber.util;


import java.awt.*;
import java.util.Vector;
import javax.swing.*;
import javax.swing.border.*;
import java.awt.event.*;

import javax.swing.event.*;
import com.borland.jbcl.layout.*;
import java.beans.*;

import javax.swing.JDialog;


class SelectionReturnValue
{
  public String tname;
  public boolean isShared;
}

public class SearchableComboSelectionDialog extends JDialog
{

  public SearchableComboSelectionDialog(JFrame parent)
  {
    super(parent, true);
    try
    {
      jbInit();
    }
    catch(Exception e) {e.printStackTrace(); }
  }

  public SearchableComboSelectionDialog(JDialog parent)
  {
    super(parent, true);
    try
    {
      jbInit();
    }
    catch(Exception e) {e.printStackTrace(); }
  }

  protected JPanel pParent;
  protected BorderLayout borderLayout1 = new BorderLayout();
  protected JPanel pCenter = new JPanel();
  protected JTextField tSelectionName = new JTextField();
  protected JLabel jLabel1 = new JLabel();
  protected JCheckBox chkShared = new JCheckBox();
  protected JPanel pSouth = new JPanel();
  protected JButton btnCancel = new JButton();
  protected JButton btnOk = new JButton();
  protected SelectionReturnValue selRetVal = new SelectionReturnValue();
  public static final int SAVE  	= 1;
  public static final int CANCEL	= 2;


  private void jbInit() throws Exception
  {
    pParent = (JPanel)this.getContentPane();
    pParent.setLayout(borderLayout1);
    tSelectionName.setPreferredSize(new Dimension(150, 21));
    jLabel1.setText("Selection Name");
    chkShared.setText("Shared");
    chkShared.setHorizontalTextPosition(SwingConstants.LEADING);
    btnCancel.setText("Cancel");
    btnCancel.addActionListener(new java.awt.event.ActionListener()
    {
      public void actionPerformed(ActionEvent e)
      {
        btnCancel_actionPerformed(e);
      }
    });
    btnOk.setText("Ok");
    btnOk.addActionListener(new java.awt.event.ActionListener()
    {
      public void actionPerformed(ActionEvent e)
      {
        btnOk_actionPerformed(e);
      }
    });
    pCenter.setPreferredSize(new Dimension(300, 35));
    pParent.setPreferredSize(new Dimension(320, 72));
    pParent.add(pCenter, BorderLayout.CENTER);
    pCenter.add(jLabel1, null);
    pCenter.add(tSelectionName, null);
    pCenter.add(chkShared, null);
    pParent.add(pSouth, BorderLayout.SOUTH);
    pSouth.add(btnOk, null);
    pSouth.add(btnCancel, null);

    setSize(350,150);
    pack();

  }


   void btnCancel_actionPerformed(ActionEvent e)
  {
    selRetVal = null;
    dispose();
  }

  protected void processWindowEvent(WindowEvent e)
  {
    super.processWindowEvent(e);
    if(e.getID() == WindowEvent.WINDOW_CLOSING)
    {
      selRetVal = null;
      dispose();
    }
  }

  void btnOk_actionPerformed(ActionEvent e)
  {
    selRetVal.tname = tSelectionName.getText();
    selRetVal.isShared = chkShared.isSelected();
    dispose();
  }

  void clear()
  {
    tSelectionName.setText("");
    chkShared.setSelected(false);
  }

  public SelectionReturnValue showDialog()
  {
    Dimension dlgSize = getPreferredSize();
    Dimension frmSize = this.getParent().getSize();
    Point loc = this.getParent().getLocation();
    setLocation( ( frmSize.width - dlgSize.width ) / 2 + loc.x,
		 ( frmSize.height - dlgSize.height ) / 2 + loc.y );

    show();
    return selRetVal;
  }
}
